/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;

/**
 * @author Bashan
 */
public class VideoThumbTaker {

    protected String ffmpegApp;

    public VideoThumbTaker(String ffmpegApp) {
        this.ffmpegApp = ffmpegApp;
    }

    public void getThumb(String videoFilename, String thumbFilename, int width, int height, int hour, int min, float sec)
            throws IOException, InterruptedException {

        ProcessBuilder processBuilder = new ProcessBuilder(ffmpegApp, "-y", "-i", videoFilename, "-vframes", "1",
                "-ss", hour + ":" + min + ":" + sec, "-f", "mjpeg", "-s", width + "*" + height, "-an", thumbFilename);
        Process process = processBuilder.start();
        InputStream stderr = process.getErrorStream();
        InputStreamReader isr = new InputStreamReader(stderr);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null);
        process.waitFor();
    }

    public static void main(String[] args) {
        VideoThumbTaker videoThumbTaker = new VideoThumbTaker("C:\\ffmpeg.exe");
        try {
            videoThumbTaker.getThumb("C:\\Mortal-Kombat-PS-Vita-Trailer.mp4", "C:\\documentos\\thumbTest.png", 120, 100, 0, 0, 10);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}